//
//  LeftSortsViewController.m
//  QuicklyPlay
//
//  Created by 你的温柔是我唯一沉溺 on 15/10/31.
//  Copyright © 2015年 OPteam. All rights reserved.
//

#import "LeftSortsViewController.h"
#import "AppDelegate.h"
#import "HotsCell.h"

#import "SettingViewController.h"
#import "LoginViewController.h"
#import "AboutUsViewController.h"
#import "CollectionListViewController.h"









@interface LeftSortsViewController () <UITableViewDataSource, UITableViewDelegate>




@property (weak, nonatomic) IBOutlet UITableView *leftSortTableView;

@property (weak, nonatomic) IBOutlet UIImageView *HeadImageView;

@property (strong, nonatomic) IBOutlet UILabel *nameLabel;

@end

@implementation LeftSortsViewController




-(Model *)model
{
    if (_model == nil) {
        _model = [[Model alloc]init];
    }
    return _model;
}

-(void)play
{
    self.nameLabel.text = self.model.name;
    [self.HeadImageView sd_setImageWithURL:[NSURL URLWithString:self.model.imageHeader]];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.leftSortTableView.delegate = self;
    self.leftSortTableView.dataSource = self;
    [self setExtraCellLineHidden: self.leftSortTableView];
    self.HeadImageView.userInteractionEnabled = YES;            //用户交互 打开
    //创建轻拍手势
//    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGRAction:)];
//    
//
//    
//    [self.HeadImageView addGestureRecognizer:tapGR];
    
}



-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.HeadImageView.layer.cornerRadius = 32;
    self.HeadImageView.layer.masksToBounds = YES;
    
    
   
    
//    if ( nameString != nil) {
//        
//        [ShareSDK getUserInfo:SSDKPlatformTypeQQ
//               onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error)
//         {
//             if (state == SSDKResponseStateSuccess)
//             {
//                 
//                 self.model.name = user.nickname;
//                 //self.model.imageHeader = user.rawData[""];
//                 self.model.imageHeader = user.rawData[@"figureurl_qq_1"];
//                                  [self play];
//             }
//             else
//             {
//                 NSLog(@"%@",error);
//             }
//             
//         }];
//         }
    
    
//   [ShareSDK getUserInfo:(SSDKPlatformType)platformTypeconditional:(SSDKUserQueryConditional *)conditionaonStateChanged:(SSDKGetUserStateChangedHandler)stateChangedHandler];
    
  
    
    
}


//创建毛玻璃背景




#pragma mark 轻拍手势的方法
//-(void)tapGRAction:(UITapGestureRecognizer *)sender {
//
//    NSLog(@"手势轻拍");
//
////    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
////    [tempAppDelegate.leftSlideVC closeLeftView];
////    LoginViewController *loginVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginVC"];
////    [tempAppDelegate.mainNC presentViewController:loginVC animated:NO     completion:nil];
//    
//    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//    UIAlertAction *play = [UIAlertAction actionWithTitle:@"QQ登陆" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//        
//        
//        [ShareSDK getUserInfo:SSDKPlatformTypeQQ
//               onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error)
//         {
//             if (state == SSDKResponseStateSuccess)
//             {
//                 
//                 self.model.name = user.nickname;
//                 //self.model.imageHeader = user.rawData[""];
//                 self.model.imageHeader = user.rawData[@"figureurl_qq_1"];
//                 
//                 nameString = user;
//                 
//                 [self play];
//                 
//             }
//             
//             else
//             {
//                 NSLog(@"%@",error);
//             }
//             
//         }];
//        
//    }];
//    
//    
//    UIAlertAction *down = [UIAlertAction actionWithTitle:@"微薄登陆" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//        
//        
//        [ShareSDK getUserInfo:SSDKPlatformTypeSinaWeibo
//               onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error)
//         {
//             if (state == SSDKResponseStateSuccess)
//             {
//                 
//                 self.model.name = user.rawData[@"screen_name"];
//                 
//                 self.model.imageHeader = user.rawData[@"avatar_hd"];
//                 nameString = user;
//                 
//                  [self play];
//             }
//             
//             else
//             {
//                 NSLog(@"%@",error);
//             }
//             
//         }];
//        
//        
//    }];
//    
//    UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//        
//        [alertVC dismissViewControllerAnimated:YES completion:nil];
//        
//    }];
//    [alertVC addAction:play];
//    [alertVC addAction:down];
//    [alertVC addAction:cancle];
//    
//    [self presentViewController:alertVC animated:YES completion:nil];
//    
//}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}




-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"flag" forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor clearColor];
    
    
//    if (indexPath.row == 0) {
//        cell.textLabel.text = @"登录";
//    } else
    if (indexPath.row == 0) {
        cell.textLabel.text = @"收藏列表";
    } else if (indexPath.row == 1) {
        cell.textLabel.text = @"关于我们";
    } else if (indexPath.row == 2) {
        cell.textLabel.text =@"设置";
    }
    return cell;
    
}


- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
//    if (0 == indexPath.row) {
          
//        LoginViewController *loginVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginVC"];
//        [tempAppDelegate.leftSlideVC closeLeftView];
//        [tempAppDelegate.window.rootViewController presentViewController:loginVC animated:YES completion:nil];
        
        
//        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//        UIAlertAction *play = [UIAlertAction actionWithTitle:@"QQ登陆" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//            
//            
//            [ShareSDK getUserInfo:SSDKPlatformTypeQQ
//                   onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error)
//             {
//                 if (state == SSDKResponseStateSuccess)
//                 {
//                     
//                   //  NSLog(@"nickname=%@",user.rawData);
//                     
//                     self.model.name = user.nickname;
//                     //self.model.imageHeader = user.rawData[""];
//                     self.model.imageHeader = user.rawData[@"figureurl_qq_1"];
//                     
//                     NSLog(@"%@",self.model);
//                     nameString = user;
//                      [self play];
//                     
//                 }
//                 
//                 else
//                 {
//                     NSLog(@"%@",error);
//                 }
//                 
//             }];
//            
//        }];
//        
//        
//        UIAlertAction *down = [UIAlertAction actionWithTitle:@"微薄登陆" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//            
//            
//            [ShareSDK getUserInfo:SSDKPlatformTypeSinaWeibo
//                   onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error)
//             {
//                 if (state == SSDKResponseStateSuccess)
//                 {
//                     
//                     self.model.name = user.rawData[@"screen_name"];
//                     
//                     self.model.imageHeader = user.rawData[@"avatar_hd"];
//                     
//                     NSLog(@"nickname=%@",user.rawData);
//                     nameString = user;
//                      [self play];
//                 }
//                 
//                 else
//                 {
//                     NSLog(@"%@",error);
//                 }
//                 
//             }];
//            
//            
//        }];
//        
//        UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//            
//            [alertVC dismissViewControllerAnimated:YES completion:nil];
//            
//        }];
//        [alertVC addAction:play];
//        [alertVC addAction:down];
//        [alertVC addAction:cancle];
//        
//        [self presentViewController:alertVC animated:YES completion:nil];
        
//    }
    
    if (0 == indexPath.row) {
        
        CollectionListViewController *collectionVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CollectionVC"];
        if (collectionVC.model == nil) {
            collectionVC.model = [[Model alloc]init];
        }
        collectionVC.model = self.model;
        
        
        [tempAppDelegate.leftSlideVC closeLeftView];
        [tempAppDelegate.window.rootViewController presentViewController:collectionVC animated:YES completion:nil];
        
    }
    
    if (1 == indexPath.row) {
        
        AboutUsViewController *aboutUsVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"AboutUsVC"];
        [tempAppDelegate.leftSlideVC closeLeftView];
        [tempAppDelegate.window.rootViewController presentViewController:aboutUsVC animated:YES completion:nil];
        
        }
    
    
    
    
    if (2 == indexPath.row) {
        
        SettingViewController *settingVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"SettingVC"];
        [tempAppDelegate.leftSlideVC closeLeftView];
        [tempAppDelegate.window.rootViewController presentViewController:settingVC animated:YES completion:nil];

    }

    
}


-(void)setExtraCellLineHidden: (UITableView *)tableView
{
    UIView *view = [UIView new];
    
    view.backgroundColor = [UIColor clearColor];
    
    [tableView setTableFooterView:view];
}


- (BOOL)shouldAutorotate {
    return NO;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
  

}


@end
